 package handling.channel.handler;


import client.*;
import client.anticheat.CheatingOffense;
import client.anticheat.ReportType;
import client.inventory.Equip;
import client.inventory.Item;
import client.inventory.MapleInventoryType;
import client.inventory.MapleRing;
import com.alibaba.druid.pool.DruidPooledConnection;
import constants.GameConstants;
import constants.ItemConstants;
import constants.JobConstants;
import database.DatabaseConnection;
import database.TowerRankBean;
import handling.opcode.EffectOpcode;
import handling.opcode.SendPacketOpcode;
import handling.world.WorldBroadcastService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import scripting.reactor.ReactorScriptManager;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import server.maps.*;
import server.quest.MapleQuest;
import tools.DateUtil;
import tools.MaplePacketCreator;
import tools.data.input.LittleEndianAccessor;
import tools.data.output.MaplePacketLittleEndianWriter;
import tools.packet.EffectPacket;
import tools.packet.PacketHelper;
import tools.packet.UIPacket;

import java.awt.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;








































 public class PlayersHandler {
/*  43 */   private static final Logger log = LogManager.getLogger(PlayersHandler.class.getName()); public static void Note(LittleEndianAccessor slea, MapleCharacter chr) { String name, msg; boolean fame;
     Item itemz;
     int num, i;
/*  46 */     byte type = slea.readByte();
/*  47 */     switch (type) {
       case 0:
/*  49 */         name = slea.readMapleAsciiString();
/*  50 */         msg = slea.readMapleAsciiString();
/*  51 */         fame = (slea.readByte() > 0);
/*  52 */         slea.readInt();
/*  53 */         itemz = chr.getCashInventory().findByCashId((int)slea.readLong());
/*  54 */         if (itemz == null || !itemz.getGiftFrom().equalsIgnoreCase(name) || !chr.getCashInventory().canSendNote(itemz.getUniqueId())) {
           return;
         }
         try {
/*  58 */           chr.sendNote(name, msg, fame ? 1 : 0);
/*  59 */           chr.getCashInventory().sendedNote(itemz.getUniqueId());
/*  60 */         } catch (Exception e) {
/*  61 */           e.printStackTrace();
         }
         return;









       case 1:
/*  74 */         num = slea.readShort();
/*  75 */         slea.readByte();
/*  76 */         for (i = 0; i < num; i++) {
/*  77 */           int id = slea.readInt();
/*  78 */           int giveFame = slea.readByte();
/*  79 */           chr.deleteNote(id, giveFame);
         }
         return;
     }
/*  83 */     System.out.println("Unhandled note action, " + type + ""); }



   public static void GiveFame(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) {
/*  88 */     int who = slea.readInt();
/*  89 */     int mode = slea.readByte();
/*  90 */     int famechange = (mode == 0) ? -1 : 1;
/*  91 */     MapleCharacter target = chr.getMap().getCharacterById(who);
/*  92 */     if (target == null || target == chr) {
/*  93 */       chr.getCheatTracker().registerOffense(CheatingOffense.FAMING_SELF, "不能对自身操作."); return;
     }
/*  95 */     if (chr.getLevel() < 15) {
/*  96 */       chr.getCheatTracker().registerOffense(CheatingOffense.FAMING_UNDER_15, "等级小于15级.");
       return;
     }
/*  99 */     switch (chr.canGiveFame(target)) {
       case OK:
/* 101 */         if (Math.abs(target.getFame() + famechange) <= 99999) {
/* 102 */           target.addFame(famechange);
/* 103 */           target.updateSingleStat(MapleStat.人气, target.getFame());
         }
/* 105 */         if (!chr.isGM()) {
/* 106 */           chr.hasGivenFame(target);
         }
/* 108 */         c.announce(MaplePacketCreator.giveFameResponse(mode, target.getName(), target.getFame()));
/* 109 */         target.getClient().announce(MaplePacketCreator.receiveFame(mode, chr.getName()));
         break;
       case NOT_TODAY:
/* 112 */         c.announce(MaplePacketCreator.giveFameErrorResponse(3));
         break;
       case NOT_THIS_MONTH:
/* 115 */         c.announce(MaplePacketCreator.giveFameErrorResponse(4));
         break;
     }
   }

   public static void UseDoor(LittleEndianAccessor slea, MapleCharacter chr) {
/* 121 */     int oid = slea.readInt();
/* 122 */     boolean mode = (slea.readByte() == 0);
/* 123 */     for (MapleMapObject obj : chr.getMap().getAllDoorsThreadsafe()) {
/* 124 */       MapleDoor door = (MapleDoor)obj;
/* 125 */       if (door.getOwnerId() == oid) {
/* 126 */         door.warp(chr, mode);
         break;
       }
     }
   }

   public static void UseMechDoor(LittleEndianAccessor slea, MapleCharacter chr) {
/* 133 */     int oid = slea.readInt();
/* 134 */     Point pos = slea.readPos();
/* 135 */     int mode = slea.readByte();
/* 136 */     if (chr != null) {
/* 137 */       chr.send(MaplePacketCreator.enableActions());
/* 138 */       for (MapleMapObject obj : chr.getMap().getAllMechDoorsThreadsafe()) {
/* 139 */         MechDoor door = (MechDoor)obj;
/* 140 */         if (door == null) {
           continue;
         }
/* 143 */         if (door.getOwnerId() == oid && door.getId() == mode) {
/* 144 */           chr.checkFollow();
/* 145 */           chr.getMap().movePlayer(chr, pos);
           break;
         }
       }
     }
   }




   public static void UseHolyFountain(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) {
/* 156 */     if (chr == null || chr.getMap() == null) {
       return;
     }
/* 159 */     int mode = slea.readByte();
/* 160 */     int oid = slea.readInt();
/* 161 */     int skillId = slea.readInt();
/* 162 */     Point position = slea.readPos();
/* 163 */     MapleMist mist = c.getPlayer().getMap().getMistByOid(oid);
/* 164 */     if (mist == null || !mist.isHolyFountain()) {
       return;
     }
/* 167 */     if (mist.getHealCount() > 0 && mist.getBox().contains(position)) {
/* 168 */       MapleCharacter owner = chr.getMap().getCharacterById(mist.getOwnerId());
/* 169 */       if (mist.getOwnerId() == chr.getId() || (owner != null && owner.getParty() != null && chr.getParty() != null && owner.getParty().getPartyId() == chr.getParty().getPartyId())) {
/* 170 */         int healHp = (int)(chr.getStat().getCurrentMaxHp() * mist.getSource().getX() / 100.0D);
/* 171 */         chr.addHP(healHp);
/* 172 */         mist.setHealCount(mist.getHealCount() - 1);
/* 173 */         if (chr.isAdmin()) {
/* 174 */           chr.dropMessage(5, "使用神圣源泉 - 恢复血量: " + healHp + " 百分比: " + (mist.getSource().getX() / 100.0D) + " 剩余次数: " + mist.getHealCount());
         }
/* 176 */         c.announce(EffectPacket.showOwnBuffEffect(skillId, EffectOpcode.UserEffect_SkillAffected.getValue(), chr.getLevel(), mist.getSkillLevel()));
/* 177 */         chr.getMap().broadcastMessage(chr, EffectPacket.showBuffeffect(chr, skillId, EffectOpcode.UserEffect_SkillAffected.getValue(), chr.getLevel(), mist.getSkillLevel()), false);
       }
/* 179 */     } else if (chr.isAdmin()) {
/* 180 */       chr.dropMessage(5, "使用神圣源泉出现错误 - 源泉恢复的剩余次数: " + mist.getHealCount() + " 模式: " + mode + " 是否在范围内: " + mist.getBox().contains(position));
     }
/* 182 */     c.announce(MaplePacketCreator.enableActions());
   }
   public static void TransformPlayer(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) {
     MapleCharacter search_chr;
/* 186 */     chr.updateTick(slea.readInt());
/* 187 */     short slot = slea.readShort();
/* 188 */     int itemId = slea.readInt();
/* 189 */     String target = slea.readMapleAsciiString();
/* 190 */     Item toUse = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot);
/* 191 */     if (toUse == null || toUse.getQuantity() < 1 || toUse.getItemId() != itemId) {
/* 192 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 195 */     switch (itemId) {
       case 2212000:
/* 197 */         search_chr = chr.getMap().getCharacterByName(target);
/* 198 */         if (search_chr != null) {
/* 199 */           MapleItemInformationProvider.getInstance().getItemEffect(2210023).applyTo(search_chr);
/* 200 */           search_chr.dropMessage(6, chr.getName() + " has played a prank on you!");
/* 201 */           MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, (short)1, false); break;
         }
/* 203 */         chr.dropMessage(1, "在当前地图中未找到 '" + target + "' 的玩家.");
         break;
     }

/* 207 */     c.announce(MaplePacketCreator.enableActions());
   }

   public static void HitReactor(LittleEndianAccessor slea, MapleClient c) {
/* 211 */     int oid = slea.readInt();
/* 212 */     int charPos = slea.readInt();
/* 213 */     short stance = slea.readShort();
/* 214 */     MapleReactor reactor = c.getPlayer().getMap().getReactorByOid(oid);
/* 215 */     if (reactor == null || !reactor.isAlive()) {
       return;
     }
/* 218 */     if (c.getPlayer().isAdmin()) {
/* 219 */       c.getPlayer().dropMessage(5, "攻击：" + reactor);
     }
/* 221 */     reactor.hitReactor(charPos, stance, c);
   }

   public static void TouchReactor(LittleEndianAccessor slea, MapleClient c) {
/* 225 */     int oid = slea.readInt();
/* 226 */     boolean touched = (slea.available() == 0L || slea.readByte() > 0);
/* 227 */     MapleReactor reactor = c.getPlayer().getMap().getReactorByOid(oid);
/* 228 */     if (!touched || reactor == null || !reactor.isAlive() || reactor.getTouch() == 0) {
       return;
     }

/* 232 */     if (c.getPlayer().isAdmin()) {
/* 233 */       c.getPlayer().dropMessage(5, "反应堆信息 - oid: " + oid + " 反应堆ID：" + reactor.getReactorId() + " Touch: " + reactor.getTouch() + " isTimerActive: " + reactor.isTimerActive() + " ReactorType: " + reactor.getReactorType());
     }
/* 235 */     if (reactor.getTouch() == 2) {
/* 236 */       ReactorScriptManager.getInstance().act(c, reactor);
/* 237 */     } else if (reactor.getTouch() == 1 && !reactor.isTimerActive()) {
/* 238 */       if (reactor.getReactorType() == 100) {
/* 239 */         int itemid = GameConstants.getCustomReactItem(reactor.getReactorId(), ((Integer)reactor.getReactItem().getLeft()).intValue());
/* 240 */         if (c.getPlayer().haveItem(itemid, ((Integer)reactor.getReactItem().getRight()).intValue())) {
/* 241 */           if (reactor.getArea().contains(c.getPlayer().getTruePosition())) {
/* 242 */             MapleInventoryManipulator.removeById(c, ItemConstants.getInventoryType(itemid), itemid, ((Integer)reactor.getReactItem().getRight()).intValue(), true, false);
/* 243 */             reactor.hitReactor(c);
           } else {
/* 245 */             c.getPlayer().dropMessage(5, "距离太远。请靠近后重新尝试。");
           }
         } else {
/* 248 */           c.getPlayer().dropMessage(5, "You don't have the item required.");
         }
       } else {
/* 251 */         reactor.hitReactor(c);
       }
     }
   }

   public static void UseRune(LittleEndianAccessor slea, MapleCharacter chr) {
/* 257 */     slea.readLong();
/* 258 */     int n3 = (int)(chr.getRuneNextActionTime() - System.currentTimeMillis());
/* 259 */     if (n3 >= 0 && chr.getLevel() >= 30) {
/* 260 */       if (chr.isAdmin()) {
/* 261 */         chr.send(MaplePacketCreator.RuneAction(7, 0));
       } else {
/* 263 */         long l2 = 900000L;
/* 264 */         if (n3 > l2) {
/* 265 */           chr.setRuneNextActionTime(l2);
         }
/* 267 */         chr.send(MaplePacketCreator.RuneAction(2, n3));
       }
/* 269 */     } else if (chr.getLevel() < 30) {
/* 270 */       chr.send(UIPacket.getSpecialTopMsg("使用符文必须等级达到30级以上！", 3, 20, 0));
/* 271 */       chr.sendEnableActions();
     } else {
/* 273 */       chr.send(MaplePacketCreator.RuneAction(7, 0));
     }
   }

   public static void UseRuneSkillReq(LittleEndianAccessor slea, MapleCharacter player) {
/* 278 */     boolean bl2 = (slea.readByte() == 1);
/* 279 */     if (bl2) {
/* 280 */       if (player.getMap().getAllRuneThreadsafe() != null) {
/* 281 */         ((MapleRune)player.getMap().getAllRuneThreadsafe().get(0)).applyToPlayer(player);
       }
/* 283 */       long l2 = 900000L;
/* 284 */       player.setRuneNextActionTime(l2);
     } else {
/* 286 */       int n2 = 60000;
/* 287 */       player.setRuneNextActionTime(n2);
/* 288 */       player.send(MaplePacketCreator.RuneAction(2, n2));
     }
   }

   public static void FollowRequest(LittleEndianAccessor slea, MapleClient c) {
/* 293 */     MapleCharacter tt = c.getPlayer().getMap().getCharacterById(slea.readInt());
/* 294 */     if (slea.readByte() > 0) {

/* 296 */       tt = c.getPlayer().getMap().getCharacterById(c.getPlayer().getFollowId());
/* 297 */       if (tt != null && tt.getFollowId() == c.getPlayer().getId()) {
/* 298 */         tt.setFollowOn(true);
/* 299 */         c.getPlayer().setFollowOn(true);
       } else {
/* 301 */         c.getPlayer().checkFollow();
       }
       return;
     }
/* 305 */     if (slea.readByte() > 0) {
/* 306 */       tt = c.getPlayer().getMap().getCharacterById(c.getPlayer().getFollowId());
/* 307 */       if (tt != null && tt.getFollowId() == c.getPlayer().getId() && c.getPlayer().isFollowOn()) {
/* 308 */         c.getPlayer().checkFollow();
       }
       return;
     }
/* 312 */     if (tt != null && tt.getPosition().distanceSq(c.getPlayer().getPosition()) < 10000.0D && tt.getFollowId() == 0 && c.getPlayer().getFollowId() == 0 && tt.getId() != c.getPlayer().getId()) {
/* 313 */       tt.setFollowId(c.getPlayer().getId());
/* 314 */       tt.setFollowOn(false);
/* 315 */       tt.setFollowInitiator(false);
/* 316 */       c.getPlayer().setFollowOn(false);
/* 317 */       c.getPlayer().setFollowInitiator(false);
/* 318 */       tt.getClient().announce(MaplePacketCreator.followRequest(c.getPlayer().getId()));
     } else {
/* 320 */       c.announce(MaplePacketCreator.serverNotice(1, "距离太远。"));
     }
   }

   public static void FollowReply(LittleEndianAccessor slea, MapleClient c) {
/* 325 */     if (c.getPlayer().getFollowId() > 0 && c.getPlayer().getFollowId() == slea.readInt()) {
/* 326 */       MapleCharacter tt = c.getPlayer().getMap().getCharacterById(c.getPlayer().getFollowId());
/* 327 */       if (tt != null && tt.getPosition().distanceSq(c.getPlayer().getPosition()) < 10000.0D && tt.getFollowId() == 0 && tt.getId() != c.getPlayer().getId()) {
/* 328 */         boolean accepted = (slea.readByte() > 0);
/* 329 */         if (accepted) {
/* 330 */           tt.setFollowId(c.getPlayer().getId());
/* 331 */           tt.setFollowOn(true);
/* 332 */           tt.setFollowInitiator(false);
/* 333 */           c.getPlayer().setFollowOn(true);
/* 334 */           c.getPlayer().setFollowInitiator(true);
/* 335 */           c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.followEffect(tt.getId(), c.getPlayer().getId(), null));
         } else {
/* 337 */           c.getPlayer().setFollowId(0);
/* 338 */           tt.setFollowId(0);
/* 339 */           tt.getClient().announce(MaplePacketCreator.getFollowMsg(5));
         }
       } else {
/* 342 */         if (tt != null) {
/* 343 */           tt.setFollowId(0);
/* 344 */           c.getPlayer().setFollowId(0);
         }
/* 346 */         c.announce(MaplePacketCreator.serverNotice(1, "距离太远."));
       }
     } else {
/* 349 */       c.getPlayer().setFollowId(0);
     }
   }


































   public static void DoRing(MapleClient c, String name, int itemid) {
/* 387 */     int newItemId = getMarriageNewItemId(itemid);
/* 388 */     MapleCharacter chr = c.getChannelServer().getPlayerStorage().getCharacterByName(name);




/* 393 */     int errcode = 0;
/* 394 */     if (JobConstants.is神之子(c.getPlayer().getJob())) {
/* 395 */       errcode = 21;
/* 396 */     } else if (c.getPlayer().getMarriageId() > 0) {
/* 397 */       errcode = 29;
/* 398 */     } else if (c.getPlayer().getMarriageItemId() > 0) {
/* 399 */       errcode = 27;
/* 400 */     } else if (!c.getPlayer().haveItem(itemid, 1) || itemid < 2240004 || itemid > 2240015) {
/* 401 */       errcode = 15;
/* 402 */     } else if (chr == null) {
/* 403 */       errcode = 22;
/* 404 */     } else if (JobConstants.is神之子(chr.getJob())) {
/* 405 */       errcode = 21;
/* 406 */     } else if (chr.getMapId() != c.getPlayer().getMapId()) {
/* 407 */       errcode = 23;
/* 408 */     } else if (chr.getGender() == c.getPlayer().getGender()) {
/* 409 */       errcode = 26;
/* 410 */     } else if (chr.getMarriageId() > 0) {
/* 411 */       errcode = 30;
/* 412 */     } else if (chr.getMarriageItemId() > 0) {
/* 413 */       errcode = 28;
/* 414 */     } else if (!MapleInventoryManipulator.checkSpace(c, newItemId, 1, "")) {
/* 415 */       errcode = 24;
     }
/* 417 */     else if (!MapleInventoryManipulator.checkSpace(chr.getClient(), newItemId, 1, "")) {
/* 418 */       errcode = 25;
     }

/* 421 */     if (errcode > 0) {
/* 422 */       c.announce(MaplePacketCreator.sendEngagement((byte)errcode, 0, null, null));
/* 423 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 426 */     c.getPlayer().setMarriageItemId(itemid);
/* 427 */     chr.send(MaplePacketCreator.sendEngagementRequest(c.getPlayer().getName(), c.getPlayer().getId()));
   }

   public static void RingAction(LittleEndianAccessor slea, MapleClient c) {
/* 431 */     byte mode = slea.readByte();
/* 432 */     if (mode == 0) {
/* 433 */       DoRing(c, slea.readMapleAsciiString(), slea.readInt());
/* 434 */     } else if (mode == 1) {
/* 435 */       c.getPlayer().setMarriageItemId(0);
/* 436 */     } else if (mode == 2) {
/* 437 */       boolean accepted = (slea.readByte() > 0);
/* 438 */       String name = slea.readMapleAsciiString();
/* 439 */       int id = slea.readInt();
/* 440 */       MapleCharacter chr = c.getChannelServer().getPlayerStorage().getCharacterByName(name);
/* 441 */       if (c.getPlayer().getMarriageId() > 0 || chr == null || chr.getId() != id || chr.getMarriageItemId() <= 0 || !chr.haveItem(chr.getMarriageItemId(), 1) || chr.getMarriageId() > 0 || !chr.isAlive() || chr.getEventInstance() != null || !c.getPlayer().isAlive() || c.getPlayer().getEventInstance() != null) {
/* 442 */         c.announce(MaplePacketCreator.sendEngagement((byte)31, 0, null, null));
/* 443 */         c.announce(MaplePacketCreator.enableActions());
         return;
       }
/* 446 */       if (accepted) {
/* 447 */         int itemid = chr.getMarriageItemId();
/* 448 */         int newItemId = getMarriageNewItemId(itemid);
/* 449 */         if (!MapleInventoryManipulator.checkSpace(c, newItemId, 1, "") || !MapleInventoryManipulator.checkSpace(chr.getClient(), newItemId, 1, "")) {
/* 450 */           c.announce(MaplePacketCreator.sendEngagement((byte)21, 0, null, null));
/* 451 */           c.announce(MaplePacketCreator.enableActions());
           return;
         }
         try {
/* 455 */           int[] ringID = MapleRing.makeRing(newItemId, c.getPlayer(), chr);
/* 456 */           Equip eq = (Equip)MapleItemInformationProvider.getInstance().getEquipById(newItemId, ringID[1]);
/* 457 */           MapleRing ring = MapleRing.loadFromDb(ringID[1]);
/* 458 */           if (ring != null) {
/* 459 */             eq.setRing(ring);
           }
/* 461 */           MapleInventoryManipulator.addbyItem(c, (Item)eq);
/* 462 */           eq = (Equip)MapleItemInformationProvider.getInstance().getEquipById(newItemId, ringID[0]);
/* 463 */           ring = MapleRing.loadFromDb(ringID[0]);
/* 464 */           if (ring != null) {
/* 465 */             eq.setRing(ring);
           }
/* 467 */           MapleInventoryManipulator.addbyItem(chr.getClient(), (Item)eq);
/* 468 */           MapleInventoryManipulator.removeById(chr.getClient(), MapleInventoryType.USE, chr.getMarriageItemId(), 1, false, false);
/* 469 */           chr.send(MaplePacketCreator.sendEngagement((byte)13, newItemId, chr, c.getPlayer()));
/* 470 */           chr.setMarriageId(c.getPlayer().getId());
/* 471 */           c.getPlayer().setMarriageId(chr.getId());
/* 472 */           chr.fakeRelog();
/* 473 */           c.getPlayer().fakeRelog();
/* 474 */           WorldBroadcastService.getInstance().broadcastMessage(MaplePacketCreator.yellowChat("[系统公告] 恭喜：" + c.getPlayer().getName() + " 和 " + chr.getName() + "结为夫妻。 希望你们在 " + chr.getClient().getChannelServer().getServerName() + " 游戏中玩的愉快!"));
/* 475 */         } catch (Exception e) {
/* 476 */           log.error("戒指操作错误", e);
         }
       } else {
/* 479 */         chr.send(MaplePacketCreator.sendEngagement((byte)32, 0, null, null));
       }
/* 481 */       c.announce(MaplePacketCreator.enableActions());
/* 482 */       chr.setMarriageItemId(0);
/* 483 */     } else if (mode == 3) {
/* 484 */       int itemId = slea.readInt();
/* 485 */       MapleInventoryType type = ItemConstants.getInventoryType(itemId);
/* 486 */       Item item = c.getPlayer().getInventory(type).findById(itemId);
/* 487 */       if (item != null && type == MapleInventoryType.ETC && itemId / 10000 == 421) {
/* 488 */         MapleInventoryManipulator.drop(c, type, item.getPosition(), item.getQuantity());
       }
     }
   }

   private static int getMarriageNewItemId(int itemId) {
     int newItemId;
/* 495 */     if (itemId == 2240004) {
/* 496 */       newItemId = 1112300;
/* 497 */     } else if (itemId == 2240005) {
/* 498 */       newItemId = 1112301;
/* 499 */     } else if (itemId == 2240006) {
/* 500 */       newItemId = 1112302;
/* 501 */     } else if (itemId == 2240007) {
/* 502 */       newItemId = 1112303;
/* 503 */     } else if (itemId == 2240008) {
/* 504 */       newItemId = 1112304;
/* 505 */     } else if (itemId == 2240009) {
/* 506 */       newItemId = 1112305;
/* 507 */     } else if (itemId == 2240010) {
/* 508 */       newItemId = 1112306;
/* 509 */     } else if (itemId == 2240011) {
/* 510 */       newItemId = 1112307;
/* 511 */     } else if (itemId == 2240012) {
/* 512 */       newItemId = 1112308;
/* 513 */     } else if (itemId == 2240013) {
/* 514 */       newItemId = 1112309;
/* 515 */     } else if (itemId == 2240014) {
/* 516 */       newItemId = 1112310;
/* 517 */     } else if (itemId == 2240015) {
/* 518 */       newItemId = 1112311;
     } else {
/* 520 */       throw new RuntimeException("Invalid Item Maker id");
     }
/* 522 */     return newItemId;
   }

   public static void Solomon(LittleEndianAccessor slea, MapleClient c) {
/* 526 */     c.announce(MaplePacketCreator.enableActions());
/* 527 */     c.getPlayer().updateTick(slea.readInt());
/* 528 */     Item item = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slea.readShort());
/* 529 */     if (item == null || item.getItemId() != slea.readInt() || item.getQuantity() <= 0 || c.getPlayer().getGachExp() > 0 || c.getPlayer().getLevel() > 50 || MapleItemInformationProvider.getInstance().getItemEffect(item.getItemId()).getEXP() <= 0) {
       return;
     }
/* 532 */     c.getPlayer().setGachExp(c.getPlayer().getGachExp() + MapleItemInformationProvider.getInstance().getItemEffect(item.getItemId()).getEXP());
/* 533 */     MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, item.getPosition(), (short)1, false);
/* 534 */     c.getPlayer().updateSingleStat(MapleStat.GACHAPONEXP, c.getPlayer().getGachExp());
   }

   public static void GachExp(LittleEndianAccessor slea, MapleClient c) {
/* 538 */     c.announce(MaplePacketCreator.enableActions());
/* 539 */     c.getPlayer().updateTick(slea.readInt());
/* 540 */     if (c.getPlayer().getGachExp() <= 0) {
       return;
     }
/* 543 */     c.getPlayer().gainExp((c.getPlayer().getGachExp() * GameConstants.getExpRate_Quest(c.getPlayer().getLevel())), true, true, false);
/* 544 */     c.getPlayer().setGachExp(0);
/* 545 */     c.getPlayer().updateSingleStat(MapleStat.GACHAPONEXP, 0L);
   }




   public static void Report(LittleEndianAccessor slea, MapleClient c) {
/* 552 */     ReportType type = ReportType.getById(slea.readByte());
/* 553 */     MapleCharacter other = c.getPlayer().getMap().getCharacterByName(slea.readMapleAsciiString());

/* 555 */     if (other == null || type == null || other.isIntern()) {

/* 557 */       c.getPlayer().dropMessage(1, "举报错误.");
/* 558 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 561 */     MapleQuestStatus stat = c.getPlayer().getQuestNAdd(MapleQuest.getInstance(123457));
/* 562 */     if (stat.getCustomData() == null) {
/* 563 */       stat.setCustomData("0");
     }
/* 565 */     long currentTime = System.currentTimeMillis();
/* 566 */     long theTime = Long.parseLong(stat.getCustomData());
/* 567 */     if (theTime + 7200000L > currentTime && !c.getPlayer().isIntern()) {
/* 568 */       c.getPlayer().dropMessage(5, "每2小时才能举报1次.");
     } else {
/* 570 */       stat.setCustomData(String.valueOf(currentTime));
/* 571 */       other.addReport(type);

/* 573 */       c.getPlayer().dropMessage(1, "举报完成.");
     }
/* 575 */     c.announce(MaplePacketCreator.enableActions());
   }

   public static boolean inArea(MapleCharacter chr) {
/* 579 */     for (Rectangle rect : chr.getMap().getAreas()) {
/* 580 */       if (rect.contains(chr.getTruePosition())) {
/* 581 */         return true;
       }
     }
/* 584 */     for (MapleMist mist : chr.getMap().getAllMistsThreadsafe()) {
/* 585 */       if (mist.getOwnerId() == chr.getId() && mist.getMistType() == 2 && mist.getBox().contains(chr.getTruePosition())) {
/* 586 */         return true;
       }
     }
/* 589 */     return false;
   }




   public static void LieDetector(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr, boolean isItem) {
/* 596 */     if (chr == null || chr.getMap() == null) {
       return;
     }
/* 599 */     String target = slea.readMapleAsciiString();
/* 600 */     short slot = 0;
/* 601 */     if (isItem) {
/* 602 */       if (!chr.getCheatTracker().canLieDetector()) {
/* 603 */         chr.dropMessage(1, "您已经使用过一次，暂时还无法使用测谎仪道具.");
/* 604 */         c.announce(MaplePacketCreator.enableActions());
         return;
       }
/* 607 */       slot = slea.readShort();
/* 608 */       int itemId = slea.readInt();
/* 609 */       Item toUse = chr.getInventory(MapleInventoryType.USE).getItem(slot);
/* 610 */       if (toUse == null || toUse.getQuantity() <= 0 || toUse.getItemId() != itemId || itemId != 2190000) {
/* 611 */         c.announce(MaplePacketCreator.enableActions());
         return;
       }
/* 614 */     } else if (!chr.isIntern()) {
/* 615 */       chr.getClient().disconnect(true, false);
/* 616 */       c.getSession().close();
       return;
     }
/* 619 */     if ((FieldLimitType.PotionUse.check(chr.getMap().getFieldLimit()) && isItem) || chr.getMap().getReturnMapId() == chr.getMapId()) {
/* 620 */       chr.dropMessage(5, "当前地图无法使用测谎仪.");
/* 621 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 624 */     MapleCharacter search_chr = chr.getMap().getCharacterByName(target);
/* 625 */     if (search_chr == null || search_chr.getId() == chr.getId() || (search_chr.isIntern() && !chr.isIntern())) {
/* 626 */       chr.dropMessage(1, "未找到角色.");
/* 627 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 630 */     if (search_chr.getEventInstance() != null || search_chr.getMapId() == 180000001) {
/* 631 */       chr.dropMessage(5, "当前地图无法使用测谎仪.");
/* 632 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 635 */     if (search_chr.getAntiMacro().inProgress()) {
/* 636 */       c.announce(MaplePacketCreator.LieDetectorResponse((byte)3));
/* 637 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 640 */     if ((search_chr.getAntiMacro().isPassed() && isItem) || search_chr.getAntiMacro().getAttempt() == 2) {
/* 641 */       c.announce(MaplePacketCreator.LieDetectorResponse((byte)2));
/* 642 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 645 */     if (!search_chr.getAntiMacro().startLieDetector(chr.getName(), isItem, false)) {
/* 646 */       chr.dropMessage(5, "使用测谎仪失败.");
/* 647 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 650 */     if (isItem) {
/* 651 */       MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, (short)1, false);
     }
/* 653 */     search_chr.dropMessage(5, chr.getName() + " 对你使用了测谎仪.");
   }

   public static void LieDetectorResponse(LittleEndianAccessor slea, MapleClient c) {
/* 657 */     if (c.getPlayer() == null || c.getPlayer().getMap() == null) {
       return;
     }
/* 660 */     String answer = slea.readMapleAsciiString();
/* 661 */     MapleLieDetector ld = c.getPlayer().getAntiMacro();
/* 662 */     if (!ld.inProgress() || (ld.isPassed() && ld.getLastType() == 0) || ld.getAnswer() == null || answer.length() <= 0) {
/* 663 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 666 */     if (answer.equalsIgnoreCase(ld.getAnswer())) {
/* 667 */       MapleCharacter search_chr = c.getPlayer().getMap().getCharacterByName(ld.getTester());
/* 668 */       if (search_chr != null && search_chr.getId() != c.getPlayer().getId()) {
/* 669 */         search_chr.dropMessage(5, c.getPlayer().getName() + " 通过了测谎仪的检测.");
       }
/* 671 */       c.announce(MaplePacketCreator.LieDetectorResponse((byte)12, (byte)1));
/* 672 */       c.getPlayer().gainMeso(5000L, true);
/* 673 */       ld.end();
/* 674 */       WorldBroadcastService.getInstance().broadcastGMMessage(MaplePacketCreator.serverNotice(6, "[GM消息] 玩家: " + c.getPlayer().getName() + " (等级 " + c.getPlayer().getLevel() + ") 通过了测谎仪检测。"));
/* 675 */     } else if (ld.getAttempt() < 3) {
/* 676 */       ld.startLieDetector(ld.getTester(), (ld.getLastType() == 0), true);
     } else {
/* 678 */       MapleCharacter search_chr = c.getPlayer().getMap().getCharacterByName(ld.getTester());
/* 679 */       if (search_chr != null && search_chr.getId() != c.getPlayer().getId()) {
/* 680 */         search_chr.dropMessage(5, c.getPlayer().getName() + " 没用通过测谎仪的检测，恭喜你获得7000的金币.");
/* 681 */         search_chr.gainMeso(7000L, true);
       }
/* 683 */       ld.end();
/* 684 */       c.getPlayer().getClient().announce(MaplePacketCreator.LieDetectorResponse((byte)10, (byte)4));
/* 685 */       MapleMap map = c.getChannelServer().getMapFactory().getMap(180000001);
/* 686 */       c.getPlayer().getQuestNAdd(MapleQuest.getInstance(123456)).setCustomData(String.valueOf(1800));
/* 687 */       c.getPlayer().changeMap(map, map.getPortal(0));
/* 688 */       WorldBroadcastService.getInstance().broadcastGMMessage(MaplePacketCreator.serverNotice(6, "[GM消息] 玩家: " + c.getPlayer().getName() + " (等级 " + c.getPlayer().getLevel() + ") 未通过测谎仪检测，系统将其监禁30分钟！"));
     }
   }

   public static void LieDetectorRefresh(LittleEndianAccessor slea, MapleClient c) {
/* 693 */     if (c.getPlayer() == null || c.getPlayer().getMap() == null) {
       return;
     }
/* 696 */     MapleLieDetector ld = c.getPlayer().getAntiMacro();
/* 697 */     if (ld.getAttempt() < 3) {
/* 698 */       ld.startLieDetector(ld.getTester(), (ld.getLastType() == 0), true);
     } else {
/* 700 */       ld.end();
/* 701 */       c.getPlayer().getClient().announce(MaplePacketCreator.LieDetectorResponse((byte)10, (byte)4));
/* 702 */       MapleMap map = c.getChannelServer().getMapFactory().getMap(180000001);
/* 703 */       c.getPlayer().getQuestNAdd(MapleQuest.getInstance(123456)).setCustomData(String.valueOf(1800));
/* 704 */       c.getPlayer().changeMap(map, map.getPortal(0));
/* 705 */       WorldBroadcastService.getInstance().broadcastGMMessage(MaplePacketCreator.serverNotice(6, "[GM消息] 玩家: " + c.getPlayer().getName() + " (等级 " + c.getPlayer().getLevel() + ") 未通过测谎仪检测，系统将其监禁30分钟！"));
     }
   }

   public static void updateRedLeafHigh(LittleEndianAccessor slea, MapleClient c) {
/* 710 */     slea.readInt();
/* 711 */     slea.readInt();
/* 712 */     int joejoe = slea.readInt();
/* 713 */     slea.readInt();
/* 714 */     int hermoninny = slea.readInt();
/* 715 */     slea.readInt();
/* 716 */     int littledragon = slea.readInt();
/* 717 */     slea.readInt();
/* 718 */     int ika = slea.readInt();
/* 719 */     slea.readInt();
/* 720 */     int wooden = slea.readInt();
/* 721 */     if (joejoe + hermoninny + littledragon + ika != c.getPlayer().getFriendShipToAdd()) {
/* 722 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 725 */     c.getPlayer().setFriendShipPoints(joejoe, hermoninny, littledragon, ika, wooden);
   }

   public static void getTowerRankRequest(LittleEndianAccessor slea, MapleClient c, MapleCharacter player) {
/* 729 */     if (player == null || player.getMap() == null) {
       return;
     }

/* 733 */     ArrayList<TowerRankBean> towerRankBeans = new ArrayList<>();

/* 735 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
/* 736 */         PreparedStatement ps = con.prepareStatement("SELECT * FROM `zrank_lobby` WHERE `world` = ? ORDER BY `stage` DESC, `time` ASC LIMIT 50")) {
/* 737 */       ps.setInt(1, c.getWorld());
/* 738 */       try (ResultSet rs = ps.executeQuery()) {
/* 739 */         while (rs.next()) {
/* 740 */           if (DateUtil.comparisonTime(System.currentTimeMillis(), rs.getTimestamp("logtime").getTime())) {
/* 741 */             towerRankBeans.add(new TowerRankBean(rs
/* 742 */                   .getInt("characters_id"), rs
/* 743 */                   .getString("characters_name"), rs
/* 744 */                   .getInt("stage"), rs
/* 745 */                   .getInt("time"), rs
/* 746 */                   .getTimestamp("logtime").getTime()));
           }
         }

       }

/* 752 */     } catch (SQLException e) {
/* 753 */       log.error("查询起源之塔排行失败", e);

       return;
     }

/* 758 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 759 */     mplew.writeShort(SendPacketOpcode.TOP_TOWER_RANK_RESULT.getValue());
/* 760 */     mplew.writeInt(towerRankBeans.size());
/* 761 */     towerRankBeans.forEach(it -> {
           mplew.writeInt(it.getPlayerID());
           mplew.writeInt(0);
           mplew.writeMapleNameString(it.getPlayerName());
           mplew.writeInt(it.getStage());
           mplew.writeInt(it.getTime());
           mplew.writeInt(0);
           mplew.writeLong(PacketHelper.getTime(it.getLogtime()));
         });
/* 770 */     c.announce(mplew.getPacket());

/* 772 */     towerRankBeans.clear();
   }
 }


/* Location:              C:\PGX\Server.jar!\handling\channel\handler\PlayersHandler.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */